package com.mida.bms.report.controller;

import com.mida.bms.report.entity.DocStructDefinitionSpace;
import com.mida.bms.report.service.DocStructDefinitionSpaceService;
import com.mida.bms.report.vo.DocStructDefinitionSpacePageVo;
import com.mida.bms.report.vo.DocStructDefinitionSpaceVo;
import com.mida.bms.report.vo.PageResultVo;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h1>结构化模板定义空间控制器</h1>
 * <p>
 *
 * @author jian.li on 2021/3/30 15:28
 */
@RestController
@RequestMapping("/docStructDefinitionSpace")
@CrossOrigin
public class DocStructDefinitionSpaceController {

    @Autowired
    private DocStructDefinitionSpaceService docStructDefinitionSpaceService;


    /**
     * 1、添加定义空间
     *
     * @param docStructDefinitionSpaceVo
     * @return
     */
    @PostMapping(value = "add",consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ActionResult add(@RequestBody DocStructDefinitionSpaceVo docStructDefinitionSpaceVo) {
        return docStructDefinitionSpaceService.add(docStructDefinitionSpaceVo);
    }

    /**
     * 2、更新定义空间
     *
     * @param docStructDefinitionSpaceVo
     * @return
     */
    @PostMapping(value = "update",consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ActionResult update(@RequestBody DocStructDefinitionSpaceVo docStructDefinitionSpaceVo) {
        return docStructDefinitionSpaceService.update(docStructDefinitionSpaceVo);
    }


    /**
     * 3、删除定义空间
     *
     * @param docStructDefinitionSpaceSoid 定义空间soid
     * @return null
     */
    @DeleteMapping("delete")
    @ResponseBody
    public ActionResult delete(@RequestParam(value = "docStructDefinitionSpaceSoid") long docStructDefinitionSpaceSoid) {
        return docStructDefinitionSpaceService.delete(docStructDefinitionSpaceSoid);
    }

    /**
     * 4、获取单个定义空间
     * @param docStructDefinitionSpaceSoid 定义空间soid
     * @return
     */
    @GetMapping("get")
    @ResponseBody
    public ListResult<DocStructDefinitionSpaceVo> get(@RequestParam(value = "docStructDefinitionSpaceSoid") long docStructDefinitionSpaceSoid) {
        return docStructDefinitionSpaceService.get(docStructDefinitionSpaceSoid);
    }


    /**
     * 5、分页查询定义空间
     * @param vo
     * @return
     */
    @PostMapping(value = "findPage",consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ListResult<PageResultVo<DocStructDefinitionSpaceVo>> findPage(@RequestBody DocStructDefinitionSpacePageVo vo) {
        return docStructDefinitionSpaceService.findPage(vo);
    }

    /**
     *6、定义空间名称重复性校验
     */
    @GetMapping(value = "/checkName")
    @ResponseBody
    public ActionResult checkName(@RequestParam(value = "name", required = true) String name,
                                  @RequestParam(value = "defineSpaceSoid", required = false) Long defineSpaceSoid) {
        return docStructDefinitionSpaceService.checkName(name,defineSpaceSoid);
    }

    /**
     *7、更改定义空间状态
     *
     * @param defineSpaceSoid 定义空间soid
     * @param status          状态码
     * @return
     */
    @GetMapping("/updateStatus")
    @ResponseBody
    public ActionResult updateStatus(@RequestParam(value = "status", required = true) Long status,
                                     @RequestParam(value = "defineSpaceSoid", required = true) Long defineSpaceSoid) {
        return docStructDefinitionSpaceService.updateStatus(status, defineSpaceSoid);
    }

    /**
     * 8、查询所有定义空间
     * @param searchData  搜索关键字
     * @return
     */
    @GetMapping(value = "/findAll", produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ListResult<List<DocStructDefinitionSpace>> findAll(@RequestParam(value = "searchData", required = false) String searchData,@RequestParam(value = "hospitalSoid") Long hospitalSoid) {
        return docStructDefinitionSpaceService.findAll(searchData,hospitalSoid);
    }


    /**
     * 11、根据定义空间soid查询定义空间基本信息
     * @param defineSpaceSoid 定义空间soid
     * @return
     */
    @GetMapping("selectByDefineSpaceSoid")
    @ResponseBody
    public ListResult<DocStructDefinitionSpaceVo> selectByDefineSpaceSoid(@RequestParam(value = "defineSpaceSoid") long defineSpaceSoid) {
        return docStructDefinitionSpaceService.selectByDefineSpaceSoid(defineSpaceSoid);
    }

}
